<template>
  <div class="article-detail-page" v-if="article.id">
    <nav class="nav" @click="$router.back()">
      <span class="back">&lt;</span> 面经详情
    </nav>
    <header class="header">
      <h1>{{ article.title }}</h1>
      <p>
        {{ article.time }} | {{ article.cmtcount }} 浏览量 |
        {{ article.cmtcount }} 点赞数
      </p>
      <p>
        <img :src="article.img" alt="" />
        <span>{{ article.title }}</span>
      </p>
    </header>
    <main class="body">
      {{ article.title }}
    </main>
  </div>
</template>

<script>
import axios from "axios";
// 请求地址: https://mock.boxuegu.com/mock/3083/articles/:id
// 请求方式: get
export default {
  name: "ArticleDetailPage",
  data() {
    return {
      article: {},
    };
  },
  async created() {
    // console.log(this.$route.query.id);
    console.log("动态路由传参:" + this.$route.params.id);

    const res = await axios.get("https://hmajax.itheima.net/api/news");
    this.article = res.data.data[this.$route.params.id - 1];
    if (typeof article === "undefined") {
      console.log("没数据");
      this.article = res.data.data[0];
    }
    console.log(this.article);
  },
};
</script>

<style lang="less" scoped>
.article-detail-page {
  .nav {
    height: 44px;
    border-bottom: 1px solid #e4e4e4;
    line-height: 44px;
    text-align: center;
    .back {
      font-size: 18px;
      color: #666;
      position: absolute;
      left: 10px;
      top: 0;
      transform: scale(1, 1.5);
    }
  }
  .header {
    padding: 0 15px;
    p {
      color: #999;
      font-size: 12px;
      display: flex;
      align-items: center;
    }
    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      overflow: hidden;
    }
  }
  .body {
    padding: 0 15px;
  }
}
</style>